
//String 类

public class Test {
    public static void main(String[] args) {
        //常量池
        char[] chars = new char[]{'a','b','c'};
        String str = new String(chars);
        //str.intern();//如果常量池中没有，则将str放入常量池
        String str1 = "abc";
        System.out.println(str == str1);

        //StringBuffer 和 StringBuilder 类
        //String 内容不可修改，StringBuffer 和 StringBuilder 的内容可以修改
        //StringBuffer 和 StringBuilder大部分功能是相似的
        //StringBuffer 采用同步处理，属于线程安全操作；而 StringBuilder 没有采用同步处理，属于线程不安全操作
        //不能直接赋值
        StringBuilder stringBuilder = new StringBuilder("abc");
        System.out.println(stringBuilder);

        stringBuilder.reverse();
        System.out.println(stringBuilder);

        //方式一
        String s = "abc";
        for (int i = 0; i < 50; i++) {
            str += i;
        }
        System.out.println(str);

        //方式二
        //方式二为方式一汇编代码照着意思写的
        String s1 = "abc";
        for (int i = 0; i < 50; i++) {
            StringBuilder stringBuilder1 = new StringBuilder();
            stringBuilder1.append(s1);
            stringBuilder1.append(i);
            s1 = stringBuilder1.toString();
        }
        System.out.println(s1);

        //方式三
        //方式三为方式二的优化
        String s2 = "abc";
        StringBuilder stringBuilder2 = new StringBuilder(s2);
        for (int i = 0; i < 50; i++) {
            stringBuilder2.append(i);
        }
        System.out.println(stringBuilder2);
    }
}
